package com.gitee.feizns.quickstart.mybatis.flex.query;

import com.gitee.feizns.quickstart.domain.page.PageRecordsVo;
import com.gitee.feizns.quickstart.domain.page.PageVo;
import com.mybatisflex.core.paginate.Page;
import lombok.RequiredArgsConstructor;

import java.util.List;

/**
 * 分页
 * @author feizns
 * @since 2025/3/5
 */
@RequiredArgsConstructor
public class MybatisFlexPageRecordsVoImpl<T> implements PageRecordsVo<T> {

    /**
     * 分页参数
     */
    private final Page<T> page;

    @Override
    public PageVo getPage() {
        return new PageVo() {
            @Override
            public Long getSize() {
                return Math.min(page.getPageSize(), page.getTotalRow());
            }
            @Override
            public Long getPages() {
                return page.getTotalPage();
            }
            @Override
            public Long getCurrent() {
                return page.getPageNumber();
            }
            @Override
            public Long getTotal() {
                return page.getTotalRow();
            }
        };
    }

    @Override
    public List<T> getRecords() {
        return page.getRecords();
    }

}
